package 高性能Golang

import (
	"net/http"
	"time"
)

func MysqlDB() string {
	time.Sleep(400 * time.Millisecond)
	return "ok"
}
func Home(w http.ResponseWriter, req *http.Request) {
	var resp string
	done := make(chan struct{}, 1)
	go func() {
		resp = MysqlDB()
		done <- struct{}{}
	}()
	select {
	case <-done:
	case <-time.After(200 * time.Millisecond):
		resp = "timeout"
	}
	w.Write([]byte(resp))
}
func main() {
	http.HandleFunc("/", Home)
	_ = http.ListenAndServe("127.0.0.1:3006", nil)
}
